package myvideos.provider;

import org.eclipse.jface.viewers.StyledCellLabelProvider;  
import org.eclipse.jface.viewers.StyledString;  
import org.eclipse.jface.viewers.ViewerCell;  
import org.eclipse.ui.ISharedImages;  
import org.eclipse.ui.PlatformUI;  
  
import myvideos.model.Category;  
import myvideos.model.Todo;  

public class TodoLabelProvider extends StyledCellLabelProvider{
	@Override  
    public void update(ViewerCell cell) {  
        Object element = cell.getElement();  
        StyledString text = new StyledString();  
  
        if (element instanceof Category) {  
            Category category = (Category) element;  
            text.append(category.getName());  
            cell.setImage(PlatformUI.getWorkbench().getSharedImages()  
                    .getImage(ISharedImages.IMG_OBJ_FOLDER));  
            text.append(" ( " +category.getTodos().size() + " ) ", StyledString.COUNTER_STYLER);  
        } else {  
            Todo todo = (Todo) element;  
            text.append(todo.getSummary());  
            cell.setImage(PlatformUI.getWorkbench().getSharedImages()  
                    .getImage(ISharedImages.IMG_OBJ_FILE));  
        }  
        cell.setText(text.toString());  
        cell.setStyleRanges(text.getStyleRanges());  
        super.update(cell);  
    }  
}
